package com.kemai.common.adapter

import android.content.Context
import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.kemai.common.R

/**

 *@description:学习内容适配器
 * @author: zhaoshanshan
 * @date: 2022/6/7 9:48 下午

 */
class StudyContentAdapter(private val data: Array<String>,private val context:Context,private val itemClickListener:ItemClickListener):RecyclerView.Adapter<StudyContentAdapter.ViewHolder>() {

    inner class ViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) {
       var  btContent:TextView = itemView.findViewById(R.id.bt_content)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.studycontent_item, parent, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.btContent.setBackgroundColor(Color.GRAY)
        holder.btContent.text = data[position]
        holder.btContent.setOnClickListener(View.OnClickListener {
            itemClickListener.itemClick(position)
        })

    }

    override fun getItemCount(): Int {
        return  data.size
    }
}

interface ItemClickListener{
    fun itemClick(position:Int)
}
